package snafu.implementation.actions.drop;

import java.util.List;

import snafu.framework.actions.IntentionItself;
import snafu.framework.actions.IntentionView;
import snafu.framework.agents.AgentState;
import snafu.framework.objects.WorldObject;
import snafu.framework.view.Access;
import snafu.framework.worlds.WorldMap;
import snafu.implementation.states.literals.have.HaveLiteral;

public class DropIntentionItself extends IntentionItself<DropAction> implements DropIntention {
	public DropIntentionItself(Access privacy) {
		super(privacy);
	}

	@Override
	public DropAction createAction(List<WorldObject> target) {
		return new DropAction(target, this);
	}

	@Override
	public IntentionView<DropAction> createView(Access access) {
		return new DropIntentionView(access, this);
	}

	@Override
	protected boolean checkApplicability(WorldMap perception, AgentState agent, List<WorldObject> targets) {

		// get the only target
		WorldObject target = targets.get(0);
		
		// get all have literals
		List<HaveLiteral> literals = agent.getLiterals(HaveLiteral.class);
		
		// check whether target is in inventory
		boolean contains = false;
		for (HaveLiteral literal : literals) {
			if (literal.getValue().equals(target)) {
				contains = true;
				break;
			}
		}
		
		return contains;
	}

}
